package entity

import (
	"encoding/binary"
	"sen-golang-study/go_game_study/hero_story_go_server/common"
	"sen-golang-study/go_game_study/hero_story_go_server/common/server_msg/proto_msg"
)

type MessageRouter struct{}

func NewMessageRouter() *MessageRouter {
	return &MessageRouter{}
}

func (mr *MessageRouter) GetResponsibilityByMsgCode(msgData []byte) common.ServerResponsibility {
	if len(msgData) < 4 {
		return common.GAME
	}

	// 解析消息码（跳过长度字段，读取消息码）
	msgCode := binary.BigEndian.Uint16(msgData[2:4])

	// 根据消息码确定职责
	switch proto_msg.MsgCode(msgCode) {
	case proto_msg.MsgCode_USER_LOGIN_CMD:
		return common.LOGIN
	case proto_msg.MsgCode_GET_RANK_CMD:
		return common.RANK
	default:
		return common.GAME
	}
}
